package exe;

import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class Zhishu2 {
    //改进版
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = 0;
        do {
            System.out.println("输入数字:");
            x = in.nextInt();
        } while (x < 1);
        if (x == 1) {
            System.out.println(x + "不是质数");
        } else {
            int start = 2;
            boolean zhi = true;//假定是质数
            int count = 0;//记录判断的次数
            while (start * start <= x && zhi) {
                count++;
                if (x % start == 0) {
                    zhi = false;
                }
                start++;
            }
            System.out.println("判断了" + count + "次");
            if (zhi) {
                System.out.println(x + "是质数");
            } else {
                System.out.println(x + "不是质数");
            }
        }
    }
}
